from django.contrib import admin

# Register your models here.

from . import models


class HeroInfoStackInline(admin.StackedInline):
    model = models.HeroInfo  # 要编辑的对象
    extra = 5  # 附加编辑的数量

class HeroInfoTabularInline(admin.TabularInline):
    model = models.HeroInfo
    extra = 1



#管理页面的显示样式
class BookInfoAdmin(admin.ModelAdmin):

    inlines = [HeroInfoTabularInline]

    #显示要显示的字段内容
    list_display = ['id', 'btitle', 'reads', 'bcomment']
    #每页显示的数据条数
    list_per_page = 2

    #操作项的显示位置
    actions_on_top = True
    actions_on_bottom = True

    #fields = ['btitle']
    # fieldsets = (
    #     ('基本', {'fields': ['btitle', 'bpub_date']}),
    #     ('高级', {
    #         'fields': ['bread', 'bcomment'],
    #         'classes': ('collapse',)  # 是否折叠显示
    #     })
    # )


class HeroInfoAdmin(admin.ModelAdmin):
    # 显示要显示的字段内容
    list_display = ['id', 'hname', 'read']


    #右侧栏的过滤器
    list_filter = ['hbook', 'hgender']

    #搜索框
    search_fields = ['hname']

#注册模型类之后，才能在后端管理表数据
admin.site.register(models.BookInfo, BookInfoAdmin)
admin.site.register(models.HeroInfo, HeroInfoAdmin)


admin.site.site_header = '传智书城'
admin.site.site_title = '传智书城MIS'
admin.site.index_title = '欢迎使用传智书城MIS'
